package com.Jeu;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

public class Splash1 extends ScreenActivity implements Runnable {

	public static final int SPLASH_DELAY = 1000;
	private static boolean pausing = false;
	private ScheduledExecutorService executor;
	private static final int TIME_DELAY = 3;
	private static boolean isAudio = true;



	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (isAudio) {
			Audio.init(this, new int[] { R.raw.musicbackground });
			Audio.setVolume(R.raw.musicbackground, 0);
			isAudio = false;
		}
		continueMusic = true;
		this.setContentView(R.layout.splash1);
		executor = Executors.newSingleThreadScheduledExecutor();
		executor.schedule(this, SPLASH_DELAY, TimeUnit.MILLISECONDS);

	}

	public void nextScreen() {
		continueMusic = true;
		executor.shutdown();
		Intent nextIntent = new Intent(this, Splash.class);
		this.startActivity(nextIntent);
		finish();
	}

	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			nextScreen();
		}
		return true;
	}

	protected void onResume() {
		pausing = false;
		super.onResume();
	}

	public void onPause() {
		pausing = true;
		super.onPause();
	}

	public void run() {
		if (!pausing) {
			nextScreen();
			Log.w("nextScreen", "11111111112222222222222222222");
		} else {
			executor.schedule(this, SPLASH_DELAY * TIME_DELAY,
					TimeUnit.MILLISECONDS);
		}
	}
}